package cn.bone.auth.security.base.conf;

import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class CustomEntryPoint implements AuthenticationEntryPoint{
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {

        response.setContentType("application/json;charset=utf-8");
        JSONObject obj = new JSONObject();
        obj.put("code", 1001);
        obj.put("message", "还未登录");
        obj.put("data", "");
        PrintWriter writer = response.getWriter();
        writer.write(obj.toJSONString());
        writer.flush();
    }
}
